#include "porting.h"
#include <gtest4c.h>
#include "lnthread.h"
#include "sql_dump.h"
#include <stdio.h>

int sql_dump_test (const char* sql)
{
  SQL_PARSER parser;
  SQL_NODE_PTR node;
  LN_STRING s;

  sql_parser_init (&parser);

  node = sql_parser (&parser, sql, -1);

  LN_STRING_INIT(&s);
  
  sql_dump_node (parser.statements, &s, "", 0);
  
  if (s.size > 0 )
  {
    printf( "++++sql ++++\r\n%s\r\n\r\n----dump----\r\n%s\r\n\r\n", sql, s.val );
  }
  
  LN_STRING_FREE(&s);

  sql_parser_close (&parser);

  return 0;
};


C_TEST (sql, alloc)
{
  sql_dump_test ("-- SQL Comment \r\n"
                 "/* C Comment --  */ \r\n"
                 "// */ C++ Comment \r\n"
                 "select * from aa \r\n"
                 "  where name=1234 or sex = 123.12 \nand dd=10e10");

  sql_dump_test ("select * from aa \r\n"
                 "  where name = 1234 or sex = 123 \r\n"
                 "update t as new_name set a=12312 where name=111111111111111111");

  sql_dump_test ("create table asdf (\r\n"
                  "a int, b char(10),sex char,xxx double,\r\n"
                  "num numeric(10,12),dt date,qq nchar(123),\r\n"
                  "vv char varying,tt varchar(128) )");

  sql_dump_test ("select * from a as t, (select * from b) as q where  a=\"asdas\" and n=N'asdasd'");

  sql_dump_test ("select ?:11 from b");
  sql_dump_test ("select a,b,c,?:23 from b");

};

C_TEST (sql, thread)
{
  LN_THREAD_PTR thrd = thrd_current();
}

C_TEST_CASE_BEGIN (sql_testCases)
  C_TEST_CASE (sql, alloc )
  C_TEST_CASE (sql, thread )
C_TEST_CASE_END ()
